﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System;
using Xiao.Application.Services.User;
using Xiao.Code.Entities.Users;
using Cx.NetCoreUtils.Exceptions;

namespace Xiao.Web.Controllers
{
    /// <summary>
    /// 用户模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ConsumerController : ControllerBase
    {
        private readonly IConsumerService _consumerService;
        public ConsumerController(
            IConsumerService consumerService
            )
        {
            _consumerService= consumerService;
        }
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <param name="consumer"></param>
        /// <returns></returns>
        /// <exception cref="BusinessLogicException"></exception>
        [HttpPost]
        public async Task<Guid> CreateConsumer(ConsumerDto consumer)
        {
            if (string.IsNullOrEmpty(consumer.UserNumber) || string.IsNullOrEmpty(consumer.PassWord))
            {
                throw new BusinessLogicException("账号或者密码不能为空");
            }
            return await _consumerService.CreateConsumer(consumer);
        }
        /// <summary>
        /// 获取好友信息
        /// </summary>
        /// <param name="frendId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ConsumerDto> GetFrend(Guid frendId)
        {
            return await _consumerService.GetFrend(frendId);
        }
        /// <summary>
        /// 通过账号搜索
        /// </summary>
        /// <param name="userNumber"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ConsumerDto> GetUser(string userNumber)
        {
            return await _consumerService.GetUser(userNumber);
        }
    }
}
